﻿using System;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace Studio
{
	// Token: 0x020005B3 RID: 1459
	public class MixPad : MonoBehaviour
	{
		// Token: 0x17000482 RID: 1154
		// (get) Token: 0x06002526 RID: 9510 RVA: 0x000DCD34 File Offset: 0x000DAF34
		// (set) Token: 0x06002527 RID: 9511 RVA: 0x000DCD3C File Offset: 0x000DAF3C
		public Vector2 normalize { get; private set; }

		// Token: 0x17000483 RID: 1155
		// (get) Token: 0x06002528 RID: 9512 RVA: 0x000DCD48 File Offset: 0x000DAF48
		private Rect rect
		{
			get
			{
				Vector3 position = this.imgPad.rectTransform.position;
				Rect pixelAdjustedRect = this.imgPad.GetPixelAdjustedRect();
				pixelAdjustedRect.Set(pixelAdjustedRect.x + position.x, pixelAdjustedRect.y + position.y, pixelAdjustedRect.width, pixelAdjustedRect.height);
				return pixelAdjustedRect;
			}
		}

		// Token: 0x06002529 RID: 9513 RVA: 0x000DCDA8 File Offset: 0x000DAFA8
		public void Init()
		{
			if (this.isInit)
			{
				return;
			}
			this.AddTrigger(EventTriggerType.BeginDrag, new UnityAction<BaseEventData>(this.OnBeginDrag));
			this.AddTrigger(EventTriggerType.Drag, new UnityAction<BaseEventData>(this.OnDrag));
			this.AddTrigger(EventTriggerType.EndDrag, new UnityAction<BaseEventData>(this.OnEndDrag));
			this.AddTrigger(EventTriggerType.PointerDown, new UnityAction<BaseEventData>(this.OnPointerDown));
			this.AddTrigger(EventTriggerType.PointerUp, new UnityAction<BaseEventData>(this.OnPointerUp));
			this.SetNormalize(Vector2.zero);
			this.isDrag = false;
			this.isInit = true;
		}

		// Token: 0x0600252A RID: 9514 RVA: 0x000DCE3C File Offset: 0x000DB03C
		public void SetNormalize(float _x, float _y)
		{
			this.SetNormalize(new Vector2(_x, _y));
		}

		// Token: 0x0600252B RID: 9515 RVA: 0x000DCE4C File Offset: 0x000DB04C
		public void SetNormalize(Vector2 _normalize)
		{
			this.normalize = _normalize;
			this.imgPointer.rectTransform.position = Rect.NormalizedToPoint(this.rect, this.normalize);
		}

		// Token: 0x0600252C RID: 9516 RVA: 0x000DCE7C File Offset: 0x000DB07C
		public void OnBeginDrag(BaseEventData _eventData)
		{
			this.isDrag = true;
		}

		// Token: 0x0600252D RID: 9517 RVA: 0x000DCE88 File Offset: 0x000DB088
		public void OnDrag(BaseEventData _eventData)
		{
			PointerEventData pointerEventData = _eventData as PointerEventData;
			this.SetPosition(pointerEventData.position);
		}

		// Token: 0x0600252E RID: 9518 RVA: 0x000DCEA8 File Offset: 0x000DB0A8
		public void OnEndDrag(BaseEventData _eventData)
		{
			this.isDrag = false;
		}

		// Token: 0x0600252F RID: 9519 RVA: 0x000DCEB4 File Offset: 0x000DB0B4
		public void OnPointerDown(BaseEventData _eventData)
		{
			if (this.isDrag)
			{
				return;
			}
			if (this.onPointerDown != null)
			{
				this.onPointerDown();
			}
			PointerEventData pointerEventData = _eventData as PointerEventData;
			this.SetPosition(pointerEventData.position);
		}

		// Token: 0x06002530 RID: 9520 RVA: 0x000DCEF8 File Offset: 0x000DB0F8
		public void OnPointerUp(BaseEventData _eventData)
		{
			if (this.onPointerUp != null)
			{
				this.onPointerUp();
			}
		}

		// Token: 0x06002531 RID: 9521 RVA: 0x000DCF10 File Offset: 0x000DB110
		private void AddTrigger(EventTriggerType _type, UnityAction<BaseEventData> _action)
		{
			EventTrigger.Entry entry = new EventTrigger.Entry();
			entry.eventID = _type;
			entry.callback.AddListener(delegate(BaseEventData data)
			{
				_action(data);
			});
			this.eventTrigger.triggers.Add(entry);
		}

		// Token: 0x06002532 RID: 9522 RVA: 0x000DCF60 File Offset: 0x000DB160
		private void SetPosition(Vector2 _pos)
		{
			Rect rect = this.rect;
			this.normalize = Rect.PointToNormalized(rect, this.imgPad.PixelAdjustPoint(_pos));
			this.imgPointer.rectTransform.position = Rect.NormalizedToPoint(rect, this.normalize);
			if (this.onValueChanged != null)
			{
				this.onValueChanged(this.normalize);
			}
		}

		// Token: 0x040025A4 RID: 9636
		[SerializeField]
		private Image imgPad;

		// Token: 0x040025A5 RID: 9637
		[SerializeField]
		private Image imgPointer;

		// Token: 0x040025A6 RID: 9638
		[SerializeField]
		private EventTrigger eventTrigger;

		// Token: 0x040025A8 RID: 9640
		public MixPad.OnPointerDelegate onPointerDown;

		// Token: 0x040025A9 RID: 9641
		public MixPad.OnPointerDelegate onPointerUp;

		// Token: 0x040025AA RID: 9642
		public MixPad.OnValueChangedDelegate onValueChanged;

		// Token: 0x040025AB RID: 9643
		private bool isInit;

		// Token: 0x040025AC RID: 9644
		private bool isDrag;

		// Token: 0x020005B4 RID: 1460
		// (Invoke) Token: 0x06002534 RID: 9524
		public delegate void OnPointerDelegate();

		// Token: 0x020005B5 RID: 1461
		// (Invoke) Token: 0x06002538 RID: 9528
		public delegate void OnValueChangedDelegate(Vector2 _value);
	}
}
